package com.old.people.controller;

import java.util.List;

import com.old.people.entities.Appraisal;
import com.old.people.entities.Disease;
import com.old.people.entities.Funds;
import com.old.people.entities.OrderOldPeople;
import com.old.people.entities.Service;
import com.old.people.entities.Servicer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.old.people.service.ServicerService;

@RestController
@RequestMapping("/oldpeopleservice")
public class ServicerController {
	@Autowired
	private ServicerService servicerService;

	@RequestMapping("/getService")
	@ResponseBody
	public List<Service> getService(String account_id) {
		return servicerService.getService(account_id);
	}

	@RequestMapping("/updateService")
	@ResponseBody
	public boolean updateService(String service_id, String service_name, String service_content, String service_price,
			String service_type) {
		return servicerService.updateService(service_id, service_name, service_content, service_price, service_type);
	}

	@RequestMapping("/insertService")
	@ResponseBody
	public boolean insertService(String account_id, String service_id, String service_name, String service_content,
			String service_price, String service_type) {
		return servicerService.insertService(account_id, service_id, service_name, service_content, service_price,
				service_type);
	}

	@RequestMapping("/getServicer")
	@ResponseBody
	public Servicer getServicer(String account_id) {
		return servicerService.getServicer(account_id);// 获取服务人员信息

	}
	
	@RequestMapping("/updateServicers")
	@ResponseBody
	public boolean updateServicers(String servicer_id,String servicer_name,String servicer_sex,String servicer_tel,String servicer_idcard) {
		return servicerService.updateServicers(servicer_id, servicer_name, servicer_sex, servicer_tel, servicer_idcard);
	}
	
	@RequestMapping("/getOrderOldPeople")
	@ResponseBody
	public List<OrderOldPeople> getOrderOldPeople(String account_id, int page) {
		int begin=page*3-3;
		if(begin<0) {
			begin=0;
		}
		return servicerService.getOrderOldPeople(account_id, begin);
	}
	
	@RequestMapping("/getOrderOldPeopleSum")
	@ResponseBody
	public int getOrderOldPeopleSum(String account_id) {
		int sum=(int)servicerService.getOrderOldPeopleSum(account_id);
		int page=0;
		if(sum%3>0) {
			page=sum/3+1;
		}else {
			page=sum/3;
		}
		return page;
	}
	
	@RequestMapping("/getDisease")
	@ResponseBody
	public List<Disease> getDisease(String oldpeople_id) {

		return servicerService.getDisease(oldpeople_id);
	}

	@RequestMapping("/updateDisease")
	@ResponseBody
	public boolean updateDisease(String disease_id, String disease_parameter) {

		return servicerService.updateDisease(disease_id, disease_parameter);
	}

	@RequestMapping("/insertDisease")
	@ResponseBody
	public boolean insertDisease(String disease_id, String disease_name, String disease_parameter,
			String oldpeople_id) {
		return servicerService.insertDisease(disease_id, disease_name, disease_parameter, oldpeople_id);
	}
	
	@RequestMapping("/getAppraisalpage")
	@ResponseBody
	public int getAppraisalpage(String account_id) {
		int sum=0;
		sum=(int)servicerService.getAppraisalSum(account_id);
		int page=0;
		if(sum%10>0) {
			page=sum/10+1;
		}else {
			page=sum/10;
		}
		return page;
	}

	@RequestMapping("/getAppraisal")
	@ResponseBody
	public List<Appraisal> getAppraisal(String account_id,int page) {
		int begin=page*10-10;
		if(begin<0) {
			begin=0;
		}
		return servicerService.getAppraisal(account_id, begin);
	}
	
	@RequestMapping("/getFundsPage")
	@ResponseBody
	public int getFundsPage(String account_id) {
		int sum=(int)servicerService.getFundsSum(account_id);
		int page=0;
		if(sum%10>0) {
			page=sum/10+1;
		}else {
			page=sum/10;
		}
		return page;
	}
	
	@RequestMapping("/getFunds")
	@ResponseBody
	public List<Funds> getFunds(String account_id, int page) {
		int begin=page*10-10;
		if(begin<0) {
			begin=0;
		}
		return servicerService.getFunds(account_id, begin);
	}
}
